package thread;

public class Demo5 {
    public static void main(String[] args) throws InterruptedException {

            Thread t= new Thread(()->{
                while(!Thread.currentThread().isInterrupted()){
                    System.out.println("hello thread");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {

                        e.printStackTrace();
                        break;//触发异常会结束循环
                    }
                }
            });
        t.start();
        Thread.sleep(1000);
        t.interrupt();//将中断设置为true了，但是sleep正在睡觉时被叫醒，会抛出异常，将标志位又设置成false了
        //就会再次执行
        //让程序员自行决定 线程t是否继续执行

        System.out.println("hello main");
}
    }